import { Test, TestingModule } from '@nestjs/testing';
import {HttpException, HttpStatus, INestApplication} from '@nestjs/common';
import * as request from 'supertest';
import { MainModule } from '../main.module';

/**
 * 端到端的测试
 */
describe('AppController', () => {
  let app: INestApplication;
  let userService = { getError: () => new HttpException('Forbidden', HttpStatus.FORBIDDEN) };

  beforeAll(async () => {
    const moduleFixture: TestingModule = await Test.createTestingModule({
      imports: [MainModule],
    }).compile();

    app = moduleFixture.createNestApplication();
    await app.init();
  });

  it('/ (GET)', () => {
    return request(app.getHttpServer())
      .get('/')
      .expect(200)
      .expect('Hello World!');
  });
  it(`/GET user/getError`, () => {
    return request(app.getHttpServer())
        .get('/getError')
        .expect(200)
        .expect(userService.getError());
  });
  afterAll(async () => {
    await app.close();
  });
});
